<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>網站管理系統</title>
	<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
	<link rel="stylesheet" href="/backstages/style/css/ch-ui.admin.css">
	<link rel="stylesheet" href="/backstages/style/font/css/font-awesome.min.css">
	<script type="text/javascript" src="/backstages/style/js/jquery.js"></script>
    <script type="text/javascript" src="/backstages/style/js/ch-ui.admin.js"></script>
    <script type="text/javascript" src="/backstages/style/js/jquery-1.8.3.min.js" ></script>
</head>
<body>
	<!--頭部 開始-->
	<div class="top_box">
		<div class="top_left">
			<div class="logo">網站管理系統</div>
			<ul>
				@foreach ($menu as $v)
					<li><a href="@if ($v->url != '') {{$v->url}} @else javascript:; @endif" pid="{{$v->id}}" @if ($v->id == 1) target="main" @endif class="top_menu @if ($v->id == 1) active @endif" >{{$v->menu_name}}</a></li>
				@endforeach
			</ul>
		</div>
		<div class="top_right">
			<ul>
				<li>管理員：{{session('admin')->user_name}}</li>
				<li><a href="javascript:void(0);" onclick="refresh();" title="刷新">刷新</a></li>
				<li><a href="/backstage/loginOut">退出</a></li>
			</ul>
		</div>
	</div>
	<!--頭部 結束-->

	<!--左側導航 開始-->
	<div class="menu_box">
		<ul></ul>
	</div>
	<!--左側導航 結束-->

	<!--主體部分 開始-->
	<div class="main_box">
		<iframe src="info" frameborder="0" width="100%" height="100%" name="main" id="main"></iframe> 
	</div>
	<!--主體部分 結束-->

	<!--底部 開始-->
	<div class="bottom_box">
		CopyRight © 2017. Powered By laravel.
	</div>
	<!--底部 結束-->
	<script type="text/javascript">
		// 點擊切換導航
    	$('.top_menu').click(function(){
			var id = $(this).attr('pid');
			$('.top_menu').removeClass('active');
			$(this).addClass('active');
			$.post("/backstage/getMenu", {
		        "id": id,
			    "_token":"{{csrf_token()}}"
		         },
		       function(d){
		       	if(d.res==1){
		       		menuHtml(d.data);
			        $('.menu_box').find('ul').find('li').find('h3').click(function(){
						$(this).parent('li').find('ul.sub_menu').slideToggle();
					});
					$('.menu_box ul li ul').find('li').click(function(){
						// $('.menu_box').find('li').removeClass('on');
						// console.log($(this).siblings('li'));
						$(this).addClass('on').siblings('li').removeClass('on');
						$(this).parents('li').siblings('li').find('li').removeClass('on');
					});
					$('.menu_box .sub_menu').find('li').eq(0).find('a').trigger('click');
					top.main.location.href=$('.sub_menu').find('li').eq(0).find('a').attr('href'); 
		       	}else{
		       		top.location.href=d.url;
		       	}
	        }, "json");
		})
		// 添加子導航
		function menuHtml(obj){
			var str = '';
			for (var i = 0; i <= obj.length - 1; i++) {
				
				str +='<li>';
		        str +='		<h3 ><i class="fa fa-fw '+obj[i].p.icon+'"></i>'+obj[i].p.menu_name+'</h3>';
		        str +='		<ul class="sub_menu" ';

		        if(i == 0){
		            str +='style="display: block;"';
		        }

		        str +=' >';

					for (var ii = 0; ii <= obj[i].c.length - 1; ii++) {
						var info = obj[i].c;
			            str +='        <li><a href="'+info[ii].p.url+'" target="main"><i class="fa fa-fw '+info[ii].p.icon+'"></i>'+info[ii].p.menu_name+'</a></li>';

		        	}

		        str +='    </ul>';
		        str +='</li>';
			}
			$('.menu_box>ul').html(str);
		}
		// 刷新
		function refresh() {
		    parent.main.location.reload();
		}


	</script>
</body>
</html>